package com.hoshino.momochi.util;

import com.hoshino.momochi.model.CreateTime;

import java.util.Collections;
import java.util.List;

public class SomeUtils {
    public static <R extends CreateTime> List<R> sortByCreateTime(List<R> list) {
        if (list == null) {
            return null;
        }
        Collections.sort(list, (a, b) -> {
            if (a.getCreateTime().after(b.getCreateTime())) {
                return -1;
            } else {
                return 1;
            }
        });
        return list;
    }

    public static <R extends CreateTime> List<R> sortByCommentCreateTime(List<R> list) {
        if (list == null) {
            return null;
        }
        Collections.sort(list, (a, b) -> {
            if (a.getCommentCreateTime().after(b.getCommentCreateTime())) {
                return -1;
            } else {
                return 1;
            }
        });
        return list;
    }
}
